﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class EndUI : MonoBehaviour {
    public GameObject btnContinue;
    public GameObject btnEnd;
    public Text text;

    void Start () {
        Datacenter.OnGameEnded += OnGameEnded;

        EventManager.addEventListener(btnContinue, UnityEngine.EventSystems.EventTriggerType.PointerClick, OnContinue, true);
        EventManager.addEventListener(btnEnd, UnityEngine.EventSystems.EventTriggerType.PointerClick, OnExit, true);
        gameObject.SetActive(false);
    }

    void OnContinue(BaseEventData eventData)
    {
        Datacenter.Reset();
        gameObject.SetActive(false);
    }

    void OnExit(BaseEventData eventData)
    {
        Application.Quit();
    }

    void OnGameEnded(CrossVal player)
    {
        text.text = player == CrossVal.black ? "黑棋胜" : "白棋胜";
        gameObject.SetActive(true);
        AudioManager.PlaySound("end2");
    }
}
